<template>
  <div>
    <el-table
      border
      stripe
      :data="plants"
      :height="height"
    >
      <el-table-column
        label="编号"
        width="80"
        align="center"
        type="index"
      />
      <el-table-column
        label="地块名称"
        prop="fieldAttr.name"
        align="center"
      />
      <el-table-column
        label="所属分区"
        prop="cell.name"
        align="center"
      >
        <template #default="scope">
          <span v-if="scope.row.cell">分区-{{ scope.row.cell.id }}</span>
          <span v-else>分区-1</span>
        </template>
      </el-table-column>
      <el-table-column
        label="种植作物"
        prop="crop.name"
        align="center"
      />
      <el-table-column
        label="开始时间"
        prop="started_at"
        align="center"
        :formatter="formatter"
        width="240"
      />
      <el-table-column
        label="暂停"
        prop="autopause"
        align="center"
      >
        <template v-slot="scope">
          <el-tag v-if="!scope.row.autopause" type="danger">关闭</el-tag>
          <el-tag v-else type="success">打开</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        label="自动决策"
        prop="autocare_mode"
        align="center"
      >
        <template v-slot="scope">
          <el-tag v-if="!scope.row.autocare_mode" type="danger">未设置</el-tag>
          <el-tag v-else type="success">运行中</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
        width="120"
      >
        <template slot-scope="scope">
          <el-link type="primary" icon="el-icon-setting" @click="edit(scope.row)">设置</el-link>
        </template>
      </el-table-column>
    </el-table>
  </div>

</template>

<script>
import { formatterForTable, getAttr } from '@/utils'
import { mapGetters } from 'vuex'
export default {
  props: {
    plants: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      fit: 'fill',
      height: 'calc(100vh - 168px)',
      project: this.$store.getters.project
    }
  },
  computed: {
    ...mapGetters(['crops'])
  },
  methods: {
    edit(row) {
      this.$emit('edit', row)
    },
    formatter(row, column) {
      return formatterForTable(row, column)
    },
    getAttr(value, name, datas) {
      return getAttr(value, name, datas)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>

